package com.house.rent.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.base.lib.mvp.present.BasePresenter;
import com.house.rent.App;
import com.house.rent.R;
import com.house.rent.entity.UserEntity;

import butterknife.BindView;
import butterknife.OnClick;

public class ModifyNameActivity extends BaseActivity {

    @BindView(R.id.edit_name)
    EditText mEdtName;

    public static void start(Context context) {
        Intent starter = new Intent(context, ModifyNameActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void initTop() {
        setTitle("修改密码");
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_modify_name;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initListeners() {

    }

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.btn_modify_name})
    public void onViewClick(View view) {
        String nickName = getNickName();
        if (TextUtils.isEmpty(nickName)) {
            showMessage("请输入用户名");
        }

        UserEntity userEntity = App.getInstance().getUserEntity();

        showLoading("正在操作...");
        addParams("userId", userEntity.getId());
        addParams("mobile", userEntity.getMobile());
        addParams("nickName", nickName);
        sendRequest("user/updateInfo", null);
    }

    @Override
    protected void onRequestSuccess(String reqId, Object obj) {
        super.onRequestSuccess(reqId, obj);
        showMessage("修改成功");
        App.getInstance().getUserEntity().setNickName(getNickName());
    }

    private String getNickName() {
        return mEdtName.getText().toString().trim();
    }
}
